package com.liuceng.zen.web.auth.utils;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Random;

public class RandomUtils extends org.apache.commons.lang3.RandomUtils {
  /**
   * 生成lenc长度的随机字符串
   * 
   * @param len
   * @return
   */
  public static final String PROTOTYPE =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

  public static String genRandomStr(int len) {
    char[] c = PROTOTYPE.toCharArray();
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < len; i++) {
      sb.append(c[random.nextInt(c.length)]);
    }
    return sb.toString();
  }

  /**
   * 生成某个区间的随机数
   * 
   * @param num
   * @return
   */
  public static String random(double min, double max) {
    double num = min + Math.random() * (max - min);
    DecimalFormat formater = new DecimalFormat("#.00");
    formater.setRoundingMode(RoundingMode.DOWN);
    String number = formater.format(num);
    return number;
  }
}
